<?php
class mod_search extends xmldb{
	public $total, $pagecnt, $pagenum, $pagestart, $pageend;
	
	public function getsearchs($keyword, $page=1, $psize=20){
		$srchs = array();
		foreach($this->xml->children() as $srch){
			if(empty($keyword) ||
				@stripos(strip_tags((string)$srch->title), $keyword) !== false ||
				@stripos(strip_tags((string)$srch->intro), $keyword) !== false){
					$srchs[] = (array)$srch;
			}
		}
		$this->total = count($srchs);
		$this->pagecnt = ceil($this->total/$psize);
		$this->pagenum = (int)$page;
		if($this->pagenum < 1) $this->pagenum = 1;
		if($this->pagenum > $this->pagecnt) $this->pagenum = $this->pagecnt;
		
		$this->pagestart = $this->pagenum - 5;
		if($this->pagestart < 1) $this->pagestart = 1;
		$this->pageend = $this->pagestart + 10;
		if($this->pageend > $this->pagecnt) $this->pageend = $this->pagecnt;
		
		return array_slice($srchs, ($this->pagenum-1)*$psize, $psize, true);
	}
}
?>
